home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / directx / dxf / samples / multimedia / demos / donuts3d / donuts.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  5.5 KB  |  209 lines

  1. //-----------------------------------------------------------------------------
  2. // File: Donuts.h
  3. //
  4. // Desc: Header for Donuts3D game
  5. //
  6. // Copyright (C) 1995-2000 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DONUTS_H
  9. #define DONUTS_H
  10.  
  11.  
  12. // Error codes
  13. #define DONUTS3DERR_NODIRECT3D       0x00000001
  14. #define DONUTS3DERR_NOD3DDEVICE      0x00000002
  15. #define DONUTS3DERR_NOTEXTURES       0x00000003
  16. #define DONUTS3DERR_NOGEOMETRY       0x00000004
  17. #define DONUTS3DERR_NO3DRESOURCES    0x00000005
  18. #define DONUTS3DERR_NOINPUT          0x00000006
  19.  
  20.  
  21. // States the app can be in
  22. enum{ APPSTATE_LOADSPLASH, APPSTATE_DISPLAYSPLASH, APPSTATE_ACTIVE, 
  23.       APPSTATE_BEGINLEVELSCREEN, APPSTATE_DISPLAYLEVELSCREEN };
  24.  
  25.  
  26. // Game object types
  27. enum{ OBJ_DONUT=0, OBJ_PYRAMID, OBJ_CUBE, OBJ_SPHERE, OBJ_CLOUD, OBJ_SHIP,
  28.       OBJ_BULLET };
  29.  
  30.  
  31. // Object dimensions and fixed properties
  32. #define DONUT_WIDTH        32
  33. #define DONUT_HEIGHT       32
  34. #define PYRAMID_WIDTH      32
  35. #define PYRAMID_HEIGHT     32
  36. #define SPHERE_WIDTH       16
  37. #define SPHERE_HEIGHT      16
  38. #define CUBE_WIDTH         16
  39. #define CUBE_HEIGHT        16
  40. #define CLOUD_WIDTH        32
  41. #define CLOUD_HEIGHT       32
  42. #define BULLET_WIDTH        3
  43. #define BULLET_HEIGHT       3
  44.  
  45. #define NUM_DONUT_FRAMES   30
  46. #define NUM_PYRAMID_FRAMES 40
  47. #define NUM_SPHERE_FRAMES  40
  48. #define NUM_CUBE_FRAMES    40
  49. #define NUM_BULLET_FRAMES 400
  50.  
  51. #define BULLET_XOFFSET    304
  52. #define BULLET_YOFFSET      0
  53.  
  54.  
  55. //-----------------------------------------------------------------------------
  56. // Name: struct DisplayObject
  57. // Desc: A game object that goes in the display list
  58. //-----------------------------------------------------------------------------
  59. struct DisplayObject
  60. {
  61.     DisplayObject* pNext;          // Link to next object
  62.     DisplayObject* pPrev;          // Link to previous object
  63.     
  64.     DWORD          dwType;            // Type of object
  65.     BOOL           bVisible;          // Whether the object is visible
  66.     D3DXVECTOR3    vPos;              // Position
  67.     D3DXVECTOR3    vVel;              // Velocity
  68.     FLOAT          fSize;
  69.     
  70.     // Constructor
  71.     DisplayObject( DWORD type, D3DVECTOR p, D3DVECTOR v );
  72. };
  73.  
  74.  
  75. //-----------------------------------------------------------------------------
  76. // Derived classes for displayable game objects
  77. //-----------------------------------------------------------------------------
  78. struct C3DSprite : public DisplayObject
  79. {
  80.     DWORD dwFramesPerLine;   // How anim frames are packed in bitmap
  81.     FLOAT frame;             // Current animation frame
  82.     FLOAT fMaxFrame;         // Max animation frame value
  83.     FLOAT delay;             // Frame/second
  84.     
  85.     DWORD dwColor;
  86.  
  87.     DWORD dwTextureOffsetX; // Pixel offsets into the game texture
  88.     DWORD dwTextureOffsetY;
  89.     DWORD dwTextureWidth;   // Width and height in pixels
  90.     DWORD dwTextureHeight; 
  91.     
  92.     C3DSprite( DWORD type, D3DVECTOR p, D3DVECTOR v );
  93. };
  94.  
  95.  
  96. class CDonut : public C3DSprite
  97. {
  98. public:
  99.     CDonut( D3DVECTOR p, D3DVECTOR v );
  100. };
  101.  
  102.  
  103. class CPyramid : public C3DSprite
  104. {
  105. public:
  106.     CPyramid( D3DVECTOR p, D3DVECTOR v );
  107. };
  108.  
  109.  
  110. class CSphere : public C3DSprite
  111. {
  112. public:
  113.     CSphere( D3DVECTOR p, D3DVECTOR v );
  114. };
  115.  
  116.  
  117. class CCube : public C3DSprite
  118. {
  119. public:
  120.     CCube( D3DVECTOR p, D3DVECTOR v );
  121. };
  122.  
  123.  
  124. class CCloud : public C3DSprite
  125. {
  126. public:
  127.     CCloud( D3DVECTOR p, D3DVECTOR v );
  128. };
  129.  
  130.  
  131. class CBullet : public C3DSprite
  132. {
  133. public:
  134.     CBullet( D3DVECTOR p, D3DVECTOR v, DWORD dwType );
  135. };
  136.  
  137.  
  138. class CShip : public DisplayObject
  139. {
  140. public:
  141.     FLOAT fRoll;
  142.  
  143.     FLOAT fAngle;
  144.  
  145.     BOOL  bExploded;
  146.     FLOAT fShowDelay;
  147.  
  148. public:
  149.     CShip( D3DVECTOR p );
  150. };
  151.  
  152.  
  153.  
  154.  
  155. //-----------------------------------------------------------------------------
  156. // Function prototypes
  157. //-----------------------------------------------------------------------------
  158.  
  159. // Main game functions
  160. LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
  161. HRESULT          CreateGameObjects( HWND hWnd );
  162. VOID             DestroyGameObjects();
  163.  
  164. // Sound functions
  165. HRESULT          CreateSoundObjects( HWND hWnd );
  166. VOID             DestroySoundObjects();
  167.  
  168. // Input functions
  169. HRESULT          CreateInputObjects( HWND hWnd );
  170. VOID             DestroyInputObjects();
  171. BOOL CALLBACK    ConfigureInputDevicesCB( IUnknown* pUnknown, VOID* pUserData );
  172. VOID             GetInput();
  173.  
  174. // Display functions
  175. HRESULT          CreateDisplayObjects( HWND hWnd );
  176. HRESULT          RestoreDisplayObjects();
  177. HRESULT          InvalidateDisplayObjects();
  178. HRESULT          DestroyDisplayObjects();
  179. HRESULT          SwitchDisplayModes( BOOL bFullScreen, DWORD dwWidth, DWORD dwHeight );
  180.  
  181. // Menu functions
  182. VOID             ConstructMenus();
  183. VOID             DestroyMenus();
  184. VOID             UpdateMenus();
  185.  
  186.  
  187. // Rendering functions
  188. HRESULT          FrameMove();
  189. HRESULT          RenderFrame();
  190. VOID             UpdateDisplayList();
  191. VOID             DrawDisplayList();
  192. VOID             ShowFrame();
  193.  
  194. // Misc game functions
  195. VOID             DisplayLevelIntroScreen( DWORD dwLevel );
  196. VOID             AdvanceLevel();
  197. BOOL             IsDisplayListEmpty();
  198. VOID             AddToList( DisplayObject* pObject );
  199. VOID             DeleteFromList( DisplayObject* pObject );
  200. VOID             CheckForHits();
  201. FLOAT            rnd( FLOAT low=-1.0f, FLOAT high=1.0f );
  202.  
  203. // Error handling
  204. VOID             CleanupAndDisplayError( DWORD dwError );
  205.  
  206.  
  207. #endif
  208.  
  209.